# 先安装 mlxtend

from mlxtend.classifier import StackingClassifier
from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import GradientBoostingClassifier
from xgboost.sklearn import XGBClassifier
from sklearn.metrics import classification_report
iris = load_iris()
X = iris.data
y = iris.target
lr = LogisticRegression() # 第二阶段的方法

RFC = RandomForestClassifier(n_estimators=10, max_depth=3, oob_score=True)
#RFC.fit(X, y)
ABC = AdaBoostClassifier(n_estimators=10)
#ABC.fit(X, y)
GBC = GradientBoostingClassifier()
#GBC.fit(X, y)
XGB = XGBClassifier()
#XGB.fit(X, y)

SC = StackingClassifier(classifiers=[RFC, ABC, GBC, XGB], meta_classifier=lr)
SC.fit(X, y)
print(classification_report(y, SC.predict(X)))